package com.gcb.job;

import com.gcb.constant.RedisConstant;
import com.gcb.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @Author 35235
 * @Date 2021/8/9 16:25
 * @Version 1.0
 */
public class CleanImgJob {
    @Autowired
    private JedisPool jedisPool;

    /**
     * 清理图片
     */
    public void clearImg(){
        //根据Redis中保存的两个set集合进行差值计算，获得垃圾图片名称集合
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (null!= set){
            for (String picName : set) {
                QiniuUtils.deleteFileFromQiniu(picName);
                //从Redis集合中删除图片名称
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,picName);
                System.out.println("自定义执行删除的任务：清理图片：：" + picName) ;
            }
        }
    }
}
